private void merge(List<Node> list, Node newNode) {
        Iterator<Node> iterator = list.iterator();
        while (iterator.hasNext()) {
            Node node = iterator.next();
            
            if (newNode.end < node.start) {
                newNode.print();
                node.print();
                while (iterator.hasNext()) iterator.next().print();
                return;
            }
            
            if (newNode.start > node.end) {
                node.print();
            }
            else {
                newNode.start = Math.min(newNode.start, node.start);
                newNode.end = Math.max(newNode.end, node.end);
            }
        }

        newNode.print();
    }
    
    private class Node {
        int start;
        int end;
        public Node(int start, int end) {
            this.start = start;
            this.end = end;
        }
        
        public void print() {
            System.out.println(this.start + ", " + this.end);
        }
    }
